iT邦幫忙

2025 iThome 鐵人賽

DAY 8
2
Software Development

30 天的 .Net gRPC 迷途系列 第 8

Day 8 gRPC Stream 定義

  • 分享至 

  • xImage
  •  

gRPC 除了前面基本範例的一元(Unary call) 還有以下三種 Stream 方式

  • 伺服器串流(Server streaming)
  • 用戶端串流(Client streaming call)
  • 雙向串流(Bi-directional streaming)

.proto 檔裡面做下面的宣告,就可以做上面三種 Stream 的設定

以下範例來自微軟官網

syntax = "proto3";

service ExampleService {
  // 伺服器串流(Server streaming)
  rpc StreamingFromServer (ExampleRequest) returns (stream ExampleResponse);

  // 用戶端串流(Client streaming)
  rpc StreamingFromClient (stream ExampleRequest) returns (ExampleResponse);

  // 雙向串流(Bi-directional streaming)
  rpc StreamingBothWays (stream ExampleRequest) returns (stream ExampleResponse);
}

設定的部分還蠻好理解的,以上就是在 Server 端的 .proto 設定,後面接續介紹相關的 Server/Client 程式


上一篇
Day7 使用 Postman 進行 gRPC 服務測試(2)
下一篇
Day9 gRPC Server Stream 建立
系列文
30 天的 .Net gRPC 迷途9
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言